package net.carefx.info.query;


import java.util.List;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;

public class InfoDAO {
	
	private Session session = null;

	public InfoDAO() {
		Configuration config = new Configuration().configure();
		SessionFactory factory = config.buildSessionFactory();
		this.session = factory.openSession();
	}
	
	public List queryBySQL(String sql) {
		List<Object[]> list = null;		
		list =  session.createSQLQuery(sql).list();
		this.session.close();
		return list;
	}
	
	public List queryByNamedSQL(String nameSQL,String inpati_id) {
		List<Object[]> list = null;	
		if(inpati_id== null)
		list =  session.getNamedQuery(nameSQL).list();
		else
		list = session.getNamedQuery(nameSQL).setParameter("idparam",inpati_id ).list();
		//this.session.close();
		return list;
	}


}
